// pages/my/familyManage.js
const app = getApp();
import { getDocumentRectInfo } from '../../../utils/util'
var topOpacity = 0;
Page({

  /**
   * 页面的初始数据
   */
  data: {
    // 组件参数设置，传递到组件
    defaultData: {
      title: "添加住户", // 导航栏标题
      showHome: false, //是否显示回到首页按钮
      showBack: true, //是否显示返回按钮
      showLogo: false, //是否显示logo
      bgColor: 'transparent'
    },
    baseUrl: app.baseUrl,
    version: app.globalData.version,
    navBarHeight: app.globalData.navBarHeight,
    groupTour: '',//组团
    roomNum: '',//房号
    tel: '',//手机号
    verificationCode: '',//验证码
    name: "",//姓名,
    ownerRelations: '',//业主关系
    cardType: '',// 正经类型
    cardNum: '',// 证件号
    leaseTerm: '',// 租期
    grouplist: [//组团列表
      {
        id: 1,
        text: '麓溪半岛'
      },
      {
        id: 2,
        text: '碧影溪'
      },
      {
        id: 3,
        text: '悦集小区'
      }
    ],
    cardlist: [// 证件类型列表
      {
        id: 1,
        text: '身份证'
      },
      {
        id: 2,
        text: '驾驶者'
      }
    ],
    leaselist: [// 租期列表
      {
        id: 1,
        text: '1'
      },
      {
        id: 2,
        text: '2'
      }
    ],
    updataList: [],
    familyRelationShow: false,
    familyRelationship: [
      {
        id: 1,
        title1: '业主配偶',
        num1: 1,
        num2: 2,
      },
      {
        id: 2,
        title1: '业主父母',
        num1: 1,
        num2: 2,
      },
      {
        id: 3,
        title1: '业主子女',
        num1: 3,
        num2: 2,
      },
      {
        id: 4,
        title1: '其他成员',
        num1: 1,
        num2: 2,
      }
    ],
    relationshipIndex: 1,
    showMaintenance:false
  },
  onPageScroll(t) {
    if (t.scrollTop < 40) {
      topOpacity = 0
      if (this.data.topOpacity != 0) {
        this.setData({
          topOpacity: 0
        })
      }
    } else if (t.scrollTop >= 40) {
      if (topOpacity <= 1) {
        topOpacity = t.scrollTop / 100 - .4
      } else {
        topOpacity = 1
      }
      if (topOpacity <= 1) {
        this.setData({
          topOpacity: topOpacity
        })
      }
    }
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad(options) {
    var that = this;

  },
  maintenance(){
    this.setData({
      showMaintenance:false
    })
  },
  popclose(){
    this.setData({
      showMaintenance:false
    })
  },
  toastHand(e) {
    wx.showToast({
      title: e,
      icon: 'none'
    })
  },
  addNember() {
    const { groupTour, roomNum, tel, verificationCode, name, ownerRelations, cardType, cardNum, leaseTerm, updataList } = this.data
    if (groupTour === '') {
      this.toastHand('请选择组团')
    } else if (roomNum === '') {
      this.toastHand('请输入房号')
    } else if (tel=== '') {
      this.toastHand('请输入电话')
    } else if (tel.length !== 11) {
      this.toastHand('请输入正确的电话')
    } else if (verificationCode === '') {
      this.toastHand('请输入验证码')
    } else if (name === '') {
      this.toastHand('请输入姓名')
    } else if (ownerRelations === '') {
      this.toastHand('请输入与业主关系')
    } else if (cardType === '') {
      this.toastHand('请选择证件类型')
    } else if (cardNum === '') {
      this.toastHand('请输入证件号')
    } else if (leaseTerm === '') {
      this.toastHand('请选择租期')
    } else if (updataList.length > 0) {
      this.toastHand('请上传图片')
    } else {
      this.toastHand('完成')
    }
  },
  selectGx(){
    this.setData({
      familyRelationShow:true
    })
  },
  relationshipBtn() {
    const { relationshipIndex, familyRelationship } = this.data
    this.setData({
      familyRelationShow: false,
      ownerRelations: familyRelationship.find(el => el.id == relationshipIndex).title1
    })
  },
  relationshipIiem(e) {
    const { id } = e.currentTarget.dataset
    this.setData({
      relationshipIndex: id
    })
  },
  //从本地获取照片 
  getLocalityImg() {
    let that = this;
    wx.chooseImage({
      count: 9,
      sizeType: ['original', 'compressed'],
      sourceType: ['album', 'camera'],
      success(res) {
        const tempFiles = res.tempFiles
        let answer = tempFiles.every(item => {
          return item.size <= 10 * 1024 * 1024
        })
        if (answer) {
          const addpic = res.tempFiles.map(el => el.path)
          that.setData({
            updataList: [...that.data.updataList, ...addpic]
          })
        } else {
          app.showTip("上传图片不能大于" + 10 + "M哦");
        }
      }
    })
  },
  //删除照片功能与预览照片功能 
  deleteImg(e) {
    let img_arr = this.data.updataList;
    let index = e.currentTarget.dataset.index;
    img_arr.splice(index, 1);
    this.setData({
      updataList: this.data.updataList
    })
  },
  //预览图片
  previewImg(e) {
    let index = e.currentTarget.dataset.index;
    let img_arr = this.data.updataList;
    wx.previewImage({
      current: img_arr[index],
      urls: img_arr
    })
  },

  bindMultiPickerChange(e) {
    const { type, list } = e.currentTarget.dataset
    this.setData({
      [type]: this.data[list][e.detail.value].text
    })
  },
  async onReady() {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow() {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide() {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload() {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh() {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom() {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage() {
    var that = this;
    return {
      title: that.data.shareTitle,
      path: '/pages/my/familyInvite?familyId=' + that.data.familyId + "&shareOpenid=" + that.data.openid + '&billId=' + that.data.billId,
      imageUrl: that.data.shareImg,
      success: function (res) {

      },
      fail: function (res) {

      }
    }
  }
})